﻿<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.lmpop.trade.ti_orderinfo.*"%>
<%@ page import="com.lmpop.trade.shopcart.*"%>
<%@ page import="com.lmpop.trade.tb_ordergoods.Tb_ordergoodsInfo" %>
<%@page import="java.text.DecimalFormat"%>
<%
	request.setCharacterEncoding("UTF-8");
	

	String cust_id = "";
	if(request.getParameter("cust_id")!=null){
		cust_id = request.getParameter("cust_id");
	}

	CartServices shopcart = null;
	
	if(session.getAttribute("shoppingCart") != null){
		shopcart = (CartServices)session.getAttribute("shoppingCart");
		shopcart.removeCustGoods(cust_id);
		//shopcart.clear();
	}
	
	String trade_no = "";
	if(request.getParameter("trade_no")!=null){
		trade_no = request.getParameter("trade_no");
	}
	 String gotoOnlinePay = "";
	if(request.getParameter("gotoOnlinePay")!=null){
		gotoOnlinePay = request.getParameter("gotoOnlinePay");
	}
	
	String subject="";
	if(request.getParameter("subject")!=null){
		subject = request.getParameter("subject");
	}
	
	String shipingfeetotal="";
	if(request.getParameter("shipingfeetotal")!=null){
		shipingfeetotal = request.getParameter("shipingfeetotal");
	}
	
	Tb_ordergoodsInfo tb_ordergoodsInfo =new Tb_ordergoodsInfo();
	Ti_orderinfoInfo ti_orderinfo = new Ti_orderinfoInfo();

	List  orderList =  null;
	List ordergoodsList = null;
	
	String all_total_amount="";
	if(request.getParameter("all_total_amount")!=null){
		all_total_amount = request.getParameter("all_total_amount");
	}
	String all_user_money="";
	if(request.getParameter("all_user_money")!=null){
		all_user_money = request.getParameter("all_user_money");
	}

	String all_voucher_money="";
	if(request.getParameter("all_voucher_money")!=null){
		all_voucher_money = request.getParameter("all_voucher_money");
	}
	
	String shipping_name="";
	if(request.getParameter("shipping_name")!=null){
		shipping_name = request.getParameter("shipping_name");
	}
	String payment_name="",payment_id = "1";	;
	if(request.getParameter("pay_name")!=null){
		payment_name = request.getParameter("pay_name");
	}
	if(request.getParameter("payment_id")!=null){
		payment_id = request.getParameter("payment_id");
		if (payment_id.equals("0")) payment_name = "货到付款";
	}
	
	DecimalFormat df = new DecimalFormat("####.00");
	String out_trade_no =  trade_no;	//请与贵网站订单系统中的唯一订单号匹配
	String price = all_total_amount;						//订单总金额，显示在支付宝收银台里的“商品单价”里

	//String voucher_price="";
	//String logistics_fee = shipingfeetotal;				//物流费用，即运费。
//	String subject = "订单:"+out_trade_no;//request.getParameter("subject");//订单名称，显示在支付宝收银台里的“商品名称”里，显示在支付宝的交易管理的“商品名称”的列表里。
	String body = "订单:"+out_trade_no;	//request.getParameter("body");//订单描述、订单详细、订单备注，显示在支付宝收银台里的“商品描述”里
	String logistics_type = "EXPRESS";	//request.getParameter("logistics_type");//物流类型，三个值可选：EXPRESS（快递）、POST（平邮）、EMS（EMS）
	String logistics_payment ="BUYER_PAY"; request.getParameter("logistics_payment");//物流支付方式，两个值可选：SELLER_PAY（卖家承担运费）、BUYER_PAY（买家承担运费）
	String quantity = "1";				//商品数量，建议默认为1，不改变值，把一次交易看成是一次下订单而非购买一件商品。
	String receive_name = "";			//收货人姓名，如：张三
	String receive_address = "";		//收货人地址，如：XX省XXX市XXX区XXX路XXX小区XXX栋XXX单元XXX号
	String receive_zip = "";			//收货人邮编，如：123456
	String receive_phone = "";			//收货人电话号码，如：0571-81234567
	String receive_mobile = "";			//收货人手机号码，如：13312341234
//	String shipping_name = "";	
	
	//String payment_name = "";	
	String order_state = "";
	double all_price =0;
	double all_logistics_fee =0;
	String order_no="",goods_name="",goods_num="",shop_price="",all_shipping_fee="",all_pack_fee="";
	double temp_price=0.00;
	if(all_user_money!=null && !"".equals(all_user_money) && cust_id.equals("100000000000000")){
		temp_price=Double.parseDouble(price)-Double.parseDouble(all_user_money);
		if(temp_price>0){
			price=String.valueOf(df.format(temp_price));
		}
		else
			price="0.00";
   }
	
	if(gotoOnlinePay.equals("1")){
		receive_name ="order_no";
		orderList = ti_orderinfo.getOrderInfoByNO(trade_no);
	} else{
		receive_name ="trade_no";
		orderList = ti_orderinfo.getOrderInfoByID(trade_no);
	}
	
	//获得订单号
	if(orderList!=null && orderList.size()>0){
		Hashtable map = (Hashtable)orderList.get(0);
		order_no = map.get("order_no").toString();
		all_shipping_fee = map.get("all_shipping_fee").toString();
		all_pack_fee = map.get("all_pack_fee").toString();
		
	}
	
  
	String user_id = "",user_email = "";	
	if( session.getAttribute("session_user_id") != null ){
		user_id = session.getAttribute("session_user_id").toString();
		user_email = "";
	}	

%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>订单成功页面</title>
<link href="/templets/html/shop/css/dd_qr.css" rel="stylesheet" type="text/css" />
<link href="/templets/html/shop/css/style.css" rel="stylesheet" type="text/css" />
<link  href="/templets/html/shop/css/Home.css" rel="stylesheet"/>
<script type="text/javascript" src="/js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="/templets/html/shop/js/ShopOrder.js"></script>
<style type="text/css">
	.STYLE1 {color: #FFFFFF}
</style>
</head>
<body>
<%
	if(!gotoOnlinePay.equals("1")){
%>
<div class="clearfix">
  <!--导航开始-->
  <div>
    <div>
      <script> 
  document.write("<s" + "cript type='text/javascript' src='/templets/html/shop/top.jsp?" + Math.random() + "'></scr" + "ipt>");
  TB.Header.init();  
</script>
    </div>
    <!--导航结束-->
    <div class="clear"></div>
    <!--收获信息结束-->
    
    <div class="content0">
<!--      <div><img src="/templets/html/shop/images/dd_18.gif" style=" margin-top:8px" /></div>
-->      <DIV class=tjk>
        <UL>
          <LI class=tj><img src="/templets/html/shop/images/ok.jpg" align="absmiddle" />   
            <%
							if(!payment_id.equals("0") && !price.equals("0.00"))
							{
						%>
				     		订单已提交，请尽快付款！<br/>
				    <%
				    	}
							if(price.equals("0.00"))
							{
						%>
								订单已提交，谢谢支付！</br/>						
						<%
							}
							else if (payment_id.equals("0"))
							{
						%>
				        订单已提交，我们会尽快安排发货！
				    <%
							}
						%>
          </LI>
          <LI class=zdh>
            订单金额：<B><%=all_total_amount%>元</B>(含运费：<%=all_shipping_fee%>元 包装费：<%=all_pack_fee%>元)&nbsp;&nbsp;&nbsp;&nbsp;
            <%
            if (cust_id.equals("99900000000000000"))
            {
            %>
							账户余额支付：<B><%=all_user_money%></B>元&nbsp;&nbsp;&nbsp;&nbsp;
            	剩余应付：<B><%=price%></B>元&nbsp;&nbsp;&nbsp;&nbsp;
            <%
            }
          else
          	{
            %>
           	 	应付：<B><%=price%></B>元
            <%
            }
            %>
             
			
            
			<p/>            
          </LI>
          <br>
          <li>
          	<%
	          	ordergoodsList = tb_ordergoodsInfo.getPersonalOrderDetail(order_no);
							Hashtable ordergoodsmap = new Hashtable();
						  if(ordergoodsList!=null && ordergoodsList.size()>0)
						  {
						  	subject = "";
						  	for(int k=0;k<ordergoodsList.size();k++)
						  	{
						  		ordergoodsmap = (Hashtable)ordergoodsList.get(k);
						  		if(ordergoodsmap.get("goods_name")!=null) goods_name = ordergoodsmap.get("goods_name").toString();
									if(ordergoodsmap.get("goods_num")!=null) goods_num = ordergoodsmap.get("goods_num").toString();
									if(ordergoodsmap.get("shop_price")!=null) shop_price = ordergoodsmap.get("shop_price").toString();
									subject = subject + "|"+ goods_name;
						%>
									<p><span>品名：[ <%=goods_name%> ]</span>
										 <span style="float:right;padding-right:50px">价格：<%=shop_price%></span>
										 <span style="float:right;padding-right:10px">数量：<%=goods_num%></span> 
									</p>	 
						<%
								}
						  }
          	%>          	
          </li>
           
          <hr>
          <%
							if(!payment_id.equals("0")&&!price.equals("0.00"))
							{
					%>
					
          <li class=tj>请选择支付方式</li>
          <%
            if (cust_id.equals("100000000000000"))
            {
          %>	
          <li>
          	<input type="radio" value="alipay" name="paycheck" checked/><img src="/templets/html/pub/images/alipay.gif">
          	<input type="radio" value="99bill" name="paycheck"/><img src="/templets/html/pub/images/99bill.gif">
          	<input type="radio" value="chinabank" name="paycheck"/><img src="/templets/html/pub/images/chinabank.gif">
          </li>
          <li class=zf_an>
          	<a href="####" onclick="submitOrderForm('<%=payment_id.trim()%>');"><img src="/templets/html/shop/images/dd_23.jpg" /></a> 
          </li>
          <%
          	}
         	 	else
          	{
          %>
           <li><img src="/templets/html/pub/images/dbalipay.gif"></li>
          	<li  class=zf_an>
          		
          		<a href="####" onclick="submitdbOrderForm('<%=payment_id.trim()%>');"><img src="/templets/html/shop/images/dd_23.jpg" /></a> 
          	</li>
          <%
          	}
          %>
          <%
						} 
						else if(payment_id.equals("0"))
						{
					%>
			          <li class="zf">您选择了货到付款，等待卖家发货！</li>
			    <%
						}	
					%>
          <li>完成支付后，您可以：
					  <A href="orderdetail.jsp?order_no=<%=order_no%>" target="_blank">查看订单
						</A>&nbsp;&nbsp;&nbsp;&nbsp; <A href="/">继续购物</A>&nbsp;&nbsp;&nbsp;&nbsp;
					  <%
							if(shopcart!=null&&shopcart.getAllItemsCount()>0)
							{
						%>
					  	<A href="/templets/html/order/order_sub.jsp">继续提交订单</A>&nbsp;&nbsp;&nbsp;&nbsp;
					  <%
					  	}	  
					  %>
		 
     	  	</li>
        </UL> 
      </DIV>
   </DIV>
    <!--提交框结束-->
  <div class="clear"></div>
  <!--底部开始-->
  <jsp:include page="/templets/html/shop/footer.jsp"/>
  <!--底部结束-->
</div>
<form id="paysubmit" name="paysubmit" action="" method="post" >
      <input type="hidden" name="out_trade_no" value="<%=order_no%> "/>
      <input type="hidden" name="dbout_trade_no" value="<%=order_no%> "/>
      <input type="hidden" name="subject" value="<%=subject%>"/>
	    <input type="hidden" name="cust_id" value="<%=cust_id%>"/>
	    <input type="hidden" name="dbcust_id" value="<%=cust_id%>"/>
      <input type="hidden" name="body" value="<%=body%> "/>
      <input type="hidden" name="order_num" value="<%=goods_num%>"/>
      <input type="hidden" id="price" name="price" value="<%=price%>"/>
      <input type="hidden" name="logistics_fee" value="<%=shipingfeetotal%> "/>
      <input type="hidden" name="logistics_type" value="<%=logistics_type%> "/>
      <input type="hidden" name="logistics_payment" value="<%=logistics_payment%> "/>
      <input type="hidden" name="quantity" value="<%=quantity%> "/>
      <input type="hidden" name="receive_name" value="<%=receive_name%> "/>
      <input type="hidden" name="receive_address" value="<%=receive_address%> "/>
      <input type="hidden" name="receive_zip" value="<%=receive_zip%> "/>
      <input type="hidden" name="receive_phone" value="<%=receive_phone%> "/>
      <input type="hidden" name="receive_mobile" value="<%=receive_mobile%>"/>
      <input type="hidden" name="user_id" id="user_id" value="<%=user_id%>"/>
      <input type="hidden" name="user_email" id="user_email" value="<%=user_email%>"/>
    </form>
    <form id="dbpaysubmit" name="dbpaysubmit" action="" method="post" >      
      <input type="hidden" name="dbout_trade_no" value="<%=order_no%> "/>
      <input type="hidden" name="dbsubject" value="<%=subject%>"/>	   
	    <input type="hidden" name="dbcust_id" value="<%=cust_id%>"/>
      <input type="hidden" name="dbbody" value="<%=body%> "/>
      <input type="hidden" id="dbprice" name="dbprice" value="<%=price%>"/>
      <input type="hidden" name="dblogistics_fee" value="<%=shipingfeetotal%> "/>
      <input type="hidden" name="dblogistics_type" value="<%=logistics_type%> "/>
      <input type="hidden" name="dblogistics_payment" value="<%=logistics_payment%> "/>
      <input type="hidden" name="quantity" value="<%=quantity%> "/>
      <input type="hidden" name="receive_name" value="<%=receive_name%> "/>
      <input type="hidden" name="receive_address" value="<%=receive_address%> "/>
      <input type="hidden" name="receive_zip" value="<%=receive_zip%> "/>
      <input type="hidden" name="receive_phone" value="<%=receive_phone%> "/>
      <input type="hidden" name="receive_mobile" value="<%=receive_mobile%>"/>
      <input type="hidden" name="user_id" id="user_id" value="<%=user_id%>"/>
      <input type="hidden" name="user_email" id="user_email" value="<%=user_email%>"/>
    </form>
<%
			} else{
		%>
<script>
			//submitOrderForm("<%=payment_id.trim()%>");
			</script>
<%
			}
		%>

</body>
</html>
